package com.tutor.syslib.action;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;

/**
 * Created by zzgpc on 2017-9-24.
 */

public class PermissionManager {
    public static final int REQUEST_CODE_ASK_LOCATION_PERMISSIONS = 200;//
    final public int REQUEST_CODE_ASK_IEM_PERMISSIONS = 201;//


    /**
     * 获取IEM号权限
     *
     * @param context
     */
    public static void requestIEMPermission(Context context) {
        if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE)
                != PackageManager.PERMISSION_GRANTED) {
            //申请WRITE_EXTERNAL_STORAGE权限
            ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.READ_PHONE_STATE},
                    REQUEST_CODE_ASK_LOCATION_PERMISSIONS);//自定义的code
            return;
        }
    }

    /**
     * 获取SD卡权限
     *
     * @param context
     */
    public static void requestSDPermission(Context context) {
        if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED) {
            //申请WRITE_EXTERNAL_STORAGE权限
            ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    REQUEST_CODE_ASK_LOCATION_PERMISSIONS);//自定义的code
            return;
        }
    }

    /**
     * 获取SD卡权限
     *
     * @param context
     */
    public static void requestCameraPermission(Context context) {
        if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA)
                != PackageManager.PERMISSION_GRANTED) {
            //CAMERA
            ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.CAMERA},
                    REQUEST_CODE_ASK_LOCATION_PERMISSIONS);//自定义的code
            return;
        }
    }
}
